package nccloud.hihr.entrynmg.action;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import nc.bs.framework.json.core.exception.ExceptionUtils;
import nc.itf.hihr.entrymng.IMailServer;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;

public class SendMailAction implements ICommonAction{

	@Override
	public Object doAction(IRequest request) {
		try {
			JSONObject root = JSONObject.parseObject(request.read());
			JSONArray arr1 = root.getJSONArray("toMailPsnids");
			String[] toMailPsnids = new String[arr1.size()];
			for(int i = 0; i < arr1.size(); i  ++) {
				toMailPsnids[i] = arr1.getString(i);
			}

			arr1 = root.getJSONArray("tablePsnids");
			String[] tablePsnids = new String[arr1.size()];
			for(int i = 0; i < arr1.size(); i  ++) {
				tablePsnids[i] = arr1.getString(i);
			}

			ServiceLocator.find(IMailServer.class).sendMail(toMailPsnids, tablePsnids);

		} catch (Throwable e) {
			ExceptionUtils.wrapException(e);
		}

		return null;
	}

}
